{extend name="df/tpl/base" /}

{block name="area_body"}
<fieldset class="layui-elem-field">
  <legend>节点 管理</legend>
  <div class="layui-field-box">
    {:html_head_tip('前端节点数据,点击单元格编辑')}
    <div class="layui-btn-group">
      <a href="{:url(CONTROLLER_NAME.'/set')}" class="layui-btn"><i class="layui-icon layui-icon-add-1"></i> 添加</a>
      <a data-href="{:url(CONTROLLER_NAME.'/dels')}" data-table="demo" class="layui-btn layui-btn-danger confirm js-ops"><i class="layui-icon layui-icon-delete"></i> 批量删除</a>
      <a href="{:url(CONTROLLER_NAME.'/editOne',['field'=>'status','val'=>'-1'])}" class="layui-btn confirm js-ops"><i class="fa fa-ban"></i> 批量禁用</a>
    </div>
    <table id="demo" lay-filter="fDemo"></table>
  </div>
</fieldset>
<!-- script -->
<script>
// page init
layui.use(['rb','table2','element','form','picView'], function(){
  var layer = layui.layer
  ,table = layui.table2
  ,form = layui.form
  ,rb = layui.rb
  ,$ = layui.$;

  rb.log('page','init');
  //执行渲染
  var Ltable = table.render({ elem: '#demo'
    ,url: '{:url(CONTROLLER_NAME."/ajax")}'
    // ,where: { parent : parent }
    ,method: 'get'
    ,request: { pageName: 'page',limitName: 'size' }
    ,limits: [10,30]
    ,limit: 10
    ,loading: true
    ,page: true
    ,cols:  [[
      {checkbox: true} //,fixed: 'left',LAY_CHECKED: true
      ,{field: 'id', title: 'ID', width: 50}//,sort:true,fixed: 'left'
      ,{field: 'title', title: '节点名 .', width: 100,edit: 'text'}
      ,{field: 'name', title: '系统名 .', width: 100,edit: 'text'}
      ,{field: 'desc', title: '描述 .', width: 250,edit: 'text'}
      ,{align:'left',title: '操作',width:250,toolbar: '#barDemo'} //,fixed: 'right'
    ]]
    ,done: function(res, page, count){
      // 转换数据
      //异步 res为接口返回,直接赋值 res为：{data: [], count: 99}
      // console.log(res);
      // res.data[0].username = 'done-edit';
      // console.log(page,count);
      // res.count = 100;
    }
  });

  // 单元格编辑
  table.on('edit(fDemo)', function(obj){
    // console.log(obj); // value , field ,data
    $.post('{:url(CONTROLLER_NAME."/editOne")}', { field: obj.field,val: obj.value,id:obj.data.id }, function(data){
      rb.ajaxTip(data);
    });
  });
});
</script>
<script type="text/html" id="barDemo">
<div class="layui-btn-group">
  <a href="{:url(CONTROLLER_NAME.'/detail',[],'')}?id={{ d.id }}" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-right"></i> 详情</a>
  <a href="{:url(CONTROLLER_NAME.'/set',[],'')}?id={{ d.id }}" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-edit"></i> 编辑</a>
  <a href="{:url(CONTROLLER_NAME.'/del',[],'')}?id={{ d.id }}" class="layui-btn layui-btn-sm layui-btn-danger ajax-get confirm no-alert"> <i class="layui-icon layui-icon-delete"></i> 删除</a>
</div>
</script>
{/block}